<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand"> <!--打开模式:极速模式，兼容模式，IE模式打开。-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <!--兼容IE8-->
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <!--全屏幕大小-->
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" media="screen" href="__STATIC__/login/css/style.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/login/css/reset.css"/>
    <title>二手书籍交易后台管理系统</title>
</head>
<body>
<form id="particles-js" class="login-form" method="post" action="">
    <div class="login">
        <div class="login-top">
            登录
        </div>
        <div class="login-center clearfix">
            <div class="login-center-img"><img src="__STATIC__/login/img/name.png"/></div>
            <div class="login-center-input">
                <input type="text" id="user_name" value="" placeholder="请输入您的用户名" name="username" onfocus="this.placeholder=''" onblur="this.placeholder='请输入您的用户名'"/>
                <div class="login-center-input-text">用户名</div>
            </div>
        </div>
        <div class="login-center clearfix">
            <div class="login-center-img"><img src="__STATIC__/login/img/password.png"/></div>
            <div class="login-center-input">
                <input type="password" id="password" value="" placeholder="请输入您的密码" name="password" onfocus="this.placeholder=''" onblur="this.placeholder='请输入您的密码'"/>
                <div class="login-center-input-text">密码</div>
            </div>
        </div>
        <div class="login-button" id="test">
            登录
        </div>
        <text class="reset" style="float: right;margin:20px;margin-right: 50px;font-size: 14px;color:#064C7D !important;cursor:pointer;">
            重置
        </text>
    </div>
    <div class="sk-rotating-plane"></div>
</form>
</body>
<script src="__STATIC__/login/js/particles.min.js"></script>
<script src="__STATIC__/login/js/app.js"></script>
<script src="__JS__/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="__STATIC__/layui/layui.js"></script>
<script>
    //清空session
    $.ajax({
        type:'post',
        url:'/index.php/admin/admin/clear_session',
        datatype:'json',
        contentType:'application/x-www-form-urlencoded; charset=utf-8',
    })

    //初始化layer
    var layer;
    layui.use('layer', function(){
        layer = layui.layer;
    })
    function hasClass(elem, cls) {
        cls = cls || '';
        if (cls.replace(/\s/g, '').length == 0) return false; //当cls没有参数时，返回false
        return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
    }

    function addClass(ele, cls) {
        if (!hasClass(ele, cls)) {
            ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
        }
    }

    function removeClass(ele, cls) {
        if (hasClass(ele, cls)) {
            var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
            while (newClass.indexOf(' ' + cls + ' ') >= 0) {
                newClass = newClass.replace(' ' + cls + ' ', ' ');
            }
            ele.className = newClass.replace(/^\s+|\s+$/g, '');
        }
    }
    $(document).keyup(function(event){
        if(event.keyCode ==13){
            $('.login-button').click();
        }
    });

    //登录
    document.querySelector(".login-button").onclick = function(){
        var login = new Object();
        login.name = $("#user_name").val();
        login.passwd = $("#password").val();
        if(login.name==""){
            layer.msg('用户名不能为空', {time:1500});
            return false;
        }else if(login.passwd==""){
            layer.msg('密码不能为空', {time:1500});
            return false;
        }else{
            addClass(document.querySelector(".login"), "active")
            setTimeout(function(){
                addClass(document.querySelector(".sk-rotating-plane"), "active")
                document.querySelector(".login").style.display = "none"
            },800)
            setTimeout(function(){
                //ajax
                $.ajax({
                    url: '/index.php/admin/admin/login',
                    type: 'post', //GET
                    async: true, //或false,是否异步
                    data: $('.login-form').serialize(),
                    timeout: 5000, //超时时间
                    dataType: 'json', //返回的数据格式：json/xml/html/script/jsonp/text
                    success:function (data) {
                        console.log(data);
                        if(data.code == 1){
                            layer.msg(data.msg,{time:900});
                            setTimeout(function(){location.href="/index.php/admin/index/index";},1000);
                        }
                        if(data.code == 0){
                            layer.msg(data.msg,{time:2000});
                            removeClass(document.querySelector(".login"), "active")
                            removeClass(document.querySelector(".sk-rotating-plane"), "active")
                            document.querySelector(".login").style.display = "block"
                            return false;
                        }
                    },
                })
            },2000)
        }
    }

    $(".reset").click(function(){
        $("#user_name").val('');
        $("#password").val('');
    })

    //将该页面置于iframe框顶层
    if (window.top != window.self) {
        window.top.location.href = window.self.location.href;
    }


</script>
</html>